package com.yueya.common.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Sms {

	
	public static String getHtml(String urlString) {
		try {
		StringBuffer html = new StringBuffer();
		URL url = new URL(urlString);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		InputStreamReader isr = new InputStreamReader(conn.getInputStream());
		BufferedReader br = new BufferedReader(isr);
		String temp;
		while ((temp = br.readLine()) != null) {
		html.append(temp).append("\n");
		}
		br.close();
		isr.close();
		return html.toString();
		} catch (Exception e) {
		e.printStackTrace();
		return null;
		}
		}
	
	
	/**
	 * 
	 * @param tels
	 * @param content   content 【example】
	 * @return
	 */
	public static boolean phone(String[] tels,String content){
		StringBuffer sb = new StringBuffer();
		sb.append("http://yw.jxgzfz.com:8888/smsGBK.aspx?action=send&userid=130&account=gzgxw&password=gzgxw888888");
		sb.append("&mobile=");
		for(int i = 0 ;i<tels.length;i++ ){
			sb.append(tels[i]);
			
			if(i!=tels.length-1){
				sb.append(",");
			}
		}
		sb.append("&content="+content);
		sb.append("&sendTime=&extno=");
		System.out.println(sb.toString());
		String text =getHtml(sb.toString());
	    if(text.indexOf("Success")>0){
	    	return true;
	    }else{
	    	return false;
	    }
		
	}
	
	public static void main(String[] args) {
		    System.out.println(Sms.phone(new String[]{"18918921992"}, "短信测试【赣州工信委】")); 
	}
	
	
}
